<template>
  <div class="list_container flex both-100">
    <Breadcrumb :title="pageTitle" />
    <div class="content_container">
      <el-form ref="searchMap" class="serach_wrapper flex-space-between" :inline="true" :model="searchMap" @submit.native.prevent>
        <div class="search">
          <el-form-item prop="planName" size="small">
            <el-input v-model="searchMap.planName" placeholder="请输入任务名称" clearable @clear="handleSerach()" @keyup.enter.native="getList()" />
          </el-form-item>
          <el-form-item class="flex">
            <el-button @click="handleSearch()" class="btn_primary">查询</el-button>
            <el-button @click="handleReset()" class="btn_cancel">重置</el-button>
          </el-form-item>
        </div>
        <div class="edit flex">
          <!-- <el-button icon="el-icon-plus" class="btn_primary" @click="handleAdd()">
            批量导入
          </el-button> -->
          <el-button icon="el-icon-plus" class="btn_primary" @click="handleAdd()">
            新增
          </el-button>
        </div>
      </el-form>
      <div class="table_container">
        <el-table stripe v-loading="loading" :data="projectList">
          <el-table-column type="index" label="序号" header-align="center" align="center" width="80"></el-table-column>
          <el-table-column prop="planEndTime" label="发布时间" header-align="center" align="center" width="80"></el-table-column>
          <el-table-column prop="inspectionTaskId" label="计划编号" align="center"></el-table-column>
          <el-table-column prop="planName" label="计划名称" align="center"></el-table-column>
          <el-table-column prop="planType" label="计划类型" align="center"></el-table-column>
          <el-table-column prop="taskUserName" label="执行人员" align="center"></el-table-column>
          <el-table-column prop="taskContent" label="管理人员" align="center"></el-table-column>
          <el-table-column prop="planStartTime" label="巡检开始时间" align="center"></el-table-column>
          <el-table-column prop="planEndTime" label="巡检结束时间" align="center"></el-table-column>
          <el-table-column prop="status" label="状态" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.inspection_project_type" :value="scope.row.status" />
            </template>
          </el-table-column>
          <el-table-column label="操作" width="300" align="center">
            <template slot-scope="scope">
              <!-- <span type="text" class="tag_primary" size="small" @click="handleDetails(scope.row)">详情</span> -->
              <span type="text" class="tag_warning" size="small" @click="handleDelete(scope.row)">删除</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination v-if="total>0" :total="total" :page.sync="searchMap.pageNum" :limit.sync="searchMap.pageSize" @change="getList" />
    </div>
    <ProjectDialog ref="projectDialog" @replace="replace"></ProjectDialog>
  </div>
</template>
<script>
import { listOnsite, getOnsiteById, deleteOnsite } from './api/onsite'
import ProjectDialog from './OsiDialog.vue'

export default {
  dicts: ['inspection_project_type'],
  name: 'osiProject',
  data () {
    return {
      // 搜索数据
      searchMap: {
        pageNum: 1, // 当前页
        pageSize: 10,  // 默认条数 
        keyword: undefined,
      },
      // 表格加载状态
      loading: false,
      // 条数
      total: 0,
      // 考试数据列表数据
      projectList: [],
      // 题目选择弹框
      dialogQuestionVisable: false,
    };
  },
  created () {
    this.getList()
  },
  computed: {
    pageTitle () {
      return '巡检管理'
    }
  },
  methods: {
    // 获取列表
    async getList () {
      this.loading = true;
      const response = await listOnsite(this.searchMap)
      if (response.code === 200) {
        this.projectList = response.rows
        this.total = response.total
        this.loading = false
      }
    },
    // 点击详情
    async handleDetails (row) {
      const inspectionTaskId = row.inspectionTaskId
      const response = await getOnsiteById(inspectionTaskId)
      this.$refs.projectDialog.show(response.data)
    },
    // 删除试卷
    handleDelete (row) {
      console.log(row)
      const inspectionTaskId = [row.inspectionTaskId]
      this.$confirm('是否确认编号为"' + inspectionTaskId + '"的数据项？').then(res => {
        return deleteOnsite(inspectionTaskId)
      }).then(() => {
        this.getList()
        this.$message.success('删除成功')
      })
    },
    // 点击新增
    handleAdd () {
      this.$nextTick(() => {
        this.$refs.projectDialog.show()
      })
      // this.dialogVisableExamPaper = true
    },
    // 确定返回数据
    replace () {
      this.getList()
    },
    // 查询
    handleSearch () {
      this.getList()
    },
    // 重置
    handleReset () {
      this.searchMap = {
        pageNum: 1, // 当前页
        pageSize: 10,  // 默认条数 
        keyword: undefined,
      },
        this.getList()
    }
  },
  components: {
    ProjectDialog
  }
}
</script>
<style lang='less' scoped>
</style>